package com.zyx.yygh.user.api;

import com.zyx.yygh.common.result.Result;
import com.zyx.yygh.common.utils.AuthContextHolder;
import com.zyx.yygh.model.user.UserInfo;
import com.zyx.yygh.user.service.UserInfoService;
import com.zyx.yygh.vo.user.LoginVo;
import com.zyx.yygh.vo.user.UserAuthVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author zyx
 * @version 1.0
 * @date 2022/1/22 022 12:41
 */

@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 用户手机登录接口
     *
     * @param loginVo
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo) {

        Map<String, Object> info = userInfoService.loginUser(loginVo);
        return Result.ok(info);
    }

    /**
     * 用户认证接口
     */
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo,
                           HttpServletRequest request) {

        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.ok();
    }

    /**
     * 获取用户id信息接口
     */
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){

        Long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }

}
